package com.migu.contacts.main.my.setting.account;

import static com.migu.contacts.net.Service.API;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.frank.libandroid.BaseActivity;
import com.frank.libandroid.HttpCallback;
import com.frank.libandroid.util.CountDownUtil;
import com.frank.libandroid.util.PasswordVisibleUtil;
import com.migu.contacts.BuildConfig;
import com.migu.contacts.bean.PasswordChangeRequest;
import com.migu.contacts.databinding.ActivitySettingModifyPasswordBinding;
import com.migu.contacts.util.UserCenter;

public class SettingModifyPasswordActivity extends BaseActivity<ActivitySettingModifyPasswordBinding> {
    PasswordChangeRequest request = new PasswordChangeRequest();

    @Override
    protected void initView() {
        super.initView();
        PasswordVisibleUtil.setPasswordVisible(mBinding.codeInput1, mBinding.showPwd1);
        PasswordVisibleUtil.setPasswordVisible(mBinding.codeInput2, mBinding.showPwd2);
    }

    @Override
    protected void initData() {
        mBinding.setBean(request);
        mBinding.oldPhone.setText("当前手机号" + UserCenter.userBean.mobile);
    }

    public void getCode(View view) {
        Log.d(TAG, "getCode() called with: view = [" + view + "]");
        if (TextUtils.isEmpty(UserCenter.userBean.mobile)) {
            ToastUtils.showShort("请输入手机号");
            return;
        }
        CountDownUtil.startCountDown(mBinding.verifyCode, 60);
        API.sendSms(2, UserCenter.userBean.mobile).watch(this, new HttpCallback<Boolean>() {
            @Override
            protected void onSuccess(Boolean aBoolean) {
                Log.d(TAG, "onSuccess() called with: aBoolean = [" + aBoolean + "]");
                if (aBoolean) {
                    ToastUtils.showShort("发送成功");
                    if (BuildConfig.DEBUG) {
                        request.code = "111111";
                    }
                }
            }
        });
    }

    public void confirm(View view) {
        API.passwordChange(request).watch(this, new HttpCallback<Boolean>() {
            @Override
            protected void onSuccess(Boolean aBoolean) {
                Log.d(TAG, "onSuccess() called with: aBoolean = [" + aBoolean + "]");
                if (aBoolean) {
                    ToastUtils.showShort("绑定成功");
                    finish();
                }
            }
        });
    }
}